package com.bier.fishproject.adapter;

import java.util.List;
import com.bier.fishproject.R;
import com.bier.fishproject.entity.Infos;
import com.bier.fishproject.utils.Base64Str;
import com.bier.fishproject.utils.NationUtils;
import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CardListAdapter extends BaseAdapter{
	
	private Context context;
	private List<Infos> list;
	private Infos infos;
	public CardListAdapter(Context context,List<Infos> list) {
		super();
		this.context = context;
		this.list=list;
	}

	@Override
	public int getCount() {
		return list==null ? 0 : list.size()-1;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		ViewHolder holder = null;
		if(view==null){
			holder = new ViewHolder(); 
			view = LayoutInflater.from(context).inflate(R.layout.card_item, null);
			holder.tvName=(TextView)view.findViewById(R.id.tv_ei_names);
			holder.tvSex=(TextView)view.findViewById(R.id.tv_ei_sexs);
			holder.tvMin=(TextView)view.findViewById(R.id.tv_ei_mins);
			holder.tvYear=(TextView)view.findViewById(R.id.tv_ei_years);
			holder.tvMonth=(TextView)view.findViewById(R.id.tv_ei_months);
			holder.tvDay=(TextView)view.findViewById(R.id.tv_ei_days);
			holder.tvAddress=(TextView)view.findViewById(R.id.tv_ei_addresss);
			holder.tvScodes=(TextView)view.findViewById(R.id.tv_ei_scodes);
			holder.tvPhone=(TextView)view.findViewById(R.id.tv_ci_phone);
			holder.tvBindCode=(TextView)view.findViewById(R.id.tv_ci_bindCode);
			holder.tvMoney=(TextView)view.findViewById(R.id.tv_ci_money);
			holder.tvNum=(TextView)view.findViewById(R.id.tv_ci_spendNum);
			view.setTag(holder);
		}else{
			holder=(ViewHolder)view.getTag();
		}
		infos=list.get(position);
		if(infos!=null){
			if(infos.getCtype().equals("0")){
				holder.tvName.setText(Base64Str.getFromBase64(infos.getIname()));
				if(infos.getIsex().equals("1")){
					holder.tvSex.setText("男");
				}else{
					holder.tvSex.setText("女");
				}
				holder.tvMin.setText(NationUtils.getMin(infos.getInation()));
				holder.tvAddress.setText(Base64Str.getFromBase64(infos.getAddr()));
				holder.tvScodes.setText(infos.getInum());
				holder.tvPhone.setText(infos.getPn());
				holder.tvBindCode.setText(infos.getSuname());
				holder.tvMoney.setText(infos.getCdeal());
				holder.tvNum.setText(infos.getCdealcount());
				if(!TextUtils.isEmpty(infos.getIbirth())){
					String[] str=infos.getIbirth().split("\\.");
					if(null!=str && str.length>0){
						holder.tvYear.setText(str[0]);
						holder.tvMonth.setText(str[1]);
						holder.tvDay.setText(str[2]);
					}
				}
			}
		}
		return view;
	}
	
	private class ViewHolder{
		private TextView tvName,tvSex,tvMin,tvYear,tvMonth,tvDay,tvAddress,tvScodes,tvPhone,tvBindCode,tvMoney,tvNum;
	 }

}
